package com.liujun.io.netty.ten.httpxml.code.client;

import com.liujun.io.netty.ten.httpxml.code.ch01.request.encode.HttpXmlRequest;
import com.liujun.io.netty.ten.httpxml.code.ch01.response.HttpXmlResponse;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class HttpXmlclientHandler extends SimpleChannelInboundHandler<HttpXmlResponse> {

	
	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		HttpXmlRequest request = new HttpXmlRequest(null, OrderFactory.create(123));
		ctx.writeAndFlush(request);
	}
	
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}

	@Override
	protected void messageReceived(ChannelHandlerContext ctx,
			HttpXmlResponse msg) throws Exception {
		System.out.println("The client receive response of http header is :" + msg.getHttpResponse().headers().names());
		System.out.println("The client receive response of http body is :" + msg.getResult());
	}


}
